#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=15;

int n;
LL s[N],b[N];
LL ans=-1;

void dfs(int i,int sum,LL ss,LL bs)
{
	//cout<<i<<' '<<sum<<' '<<ss<<' '<<bs<<endl;
	if(i>n)
	{
		if(sum>0)
		{
			if(ans==-1)
			{
				ans=abs(ss-bs);
			}
			else ans=min(ans,abs(ss-bs));
		}
		return;
	}
	dfs(i+1,sum+1,ss*s[i],bs+b[i]);
	dfs(i+1,sum,ss,bs);
}

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		//scanf("%lld%lld",&s[i],&b[i]);
		cin>>s[i]>>b[i];
	}
	dfs(1,0,1,0);
	cout<<ans;
	return 0;
}
